<!DOCTYPE html>
<!--
Copyright 2016 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/tracing/base/base.html">

<script>
'use strict';

tr.exportTo('tr.ui.b', function() {
  function readFile(fileBlob) {
    return new Promise(function(resolve, reject) {
      const reader = new FileReader();
      const filename = fileBlob.name;
      reader.onload = function(data) {
        resolve(data.target.result);
      };
      reader.onerror = function(err) {
        reject(err);
      };

      const isBinary = filename.endsWith('.gz') || filename.endsWith('.zip') ||
          filename.endsWith('.pftrace');
      if (isBinary) {
        reader.readAsArrayBuffer(fileBlob);
      } else {
        reader.readAsText(fileBlob);
      }
    });
  }
  return {
    readFile,
  };
});
</script>
